package kuangshen.start;

/**
 * 延时多线程，资源出现异常问题
 */
public class ThreadTest4 extends Thread{

    private int ticket = 10;

    @Override
    public void run() {
        super.run();
        while (ticket > 0){
            //模拟延时
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"拿到了"+ticket --);
        }
    }

    public static void main(String[] args) {
        //多线程操作统一资源发现程序紊乱
        ThreadTest4 threadTest4 = new ThreadTest4();
        new Thread(threadTest4,"小米").start();
        new Thread(threadTest4,"小二").start();
        new Thread(threadTest4,"小豆").start();
    }
}
